﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace RobotEscape.Entities
{
    public class MessageBox : EntityBase
    {
        public string Message { get; set; }

        public MessageBox(string message)
        {
            this.uiElement = new Rectangle();
            this.width = Game.Instance.CANVAS_WIDTH;
            this.height = 100;
            this.PosX = 0;
            this.PosY = 0;
            this.Message = message;
            this.pausable = false;
        }

        public override void Update(GameTime time)
        {
            Rectangle rect = this.uiElement as Rectangle;
            //if (rect != null)

            var imageBrush = new ImageBrush
            {
                Stretch = Stretch.None,
                AlignmentX = AlignmentX.Left,
                AlignmentY = AlignmentY.Top
            };
            WriteableBitmap wb = new WriteableBitmap(this.width, this.height);
            wb.Invalidate();
            wb.FillRectangle(0, 0, this.width, this.height, Util.RobotRed);
            Util.DrawText(wb, this.Message, 18, wb.PixelWidth / 2, wb.PixelHeight / 2 - 9, Colors.Black, TextAlignment.Center, true);
            wb.Invalidate();

            imageBrush.ImageSource = wb;
            rect.Fill = imageBrush;
            Canvas.SetLeft(rect, this.PosX);
            Canvas.SetTop(rect, this.PosY);
            rect.Width = this.width;
            rect.Height = this.height;



            base.Update(time);
        }
    }
}
